home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.02 Feb 88 / pascal sources / Plot Project Stuff / myPlotStuff < prev    next >
Encoding:
Text File  |  1988-01-08  |  7.0 KB  |  280 lines  |  [TEXT/PJMM]

  1. UNIT MyPlotStuff;
  2.  
  3. INTERFACE
  4.  
  5.     USES
  6.         ROM85, PrintTraps, PlotGlobals, Misc, solve, MyFileStuff, MyPrintStuff;
  7.  
  8.     PROCEDURE doAbout;
  9.     PROCEDURE doQuit;
  10.     PROCEDURE doMenubar (menuResult : LongInt);
  11.     PROCEDURE doContent (ConEvent : EventRecord;
  12.                                     contentWindow : windowPtr);
  13.     PROCEDURE doDrag (GrabWindow : WindowPtr;
  14.                                     GlobalMouse : point);
  15.     PROCEDURE doGrow (ResizeWindow : WindowPtr;
  16.                                     Globalmouse : point;
  17.                                     Zoomflg : Boolean);
  18.  
  19. IMPLEMENTATION
  20.  
  21.     PROCEDURE doAbout;
  22.         VAR
  23.             IDStrHandle : StringHandle;
  24.             dialogP : DialogPtr;
  25.             item : integer;
  26.             Str1, Str2, Str3 : str255;
  27.             myHeapSpace : LongInt;
  28.             FreeSpace : Size;
  29.     BEGIN
  30.         IDStrHandle := StringHandle(GetResource(rsrc, 0));
  31.         IF IDStrHandle = NIL THEN
  32.             BEGIN
  33.                 doMessage('Get About box crash!', '', '', '');
  34.                 ExitToShell;
  35.             END;
  36.         MoveHHi(Handle(IDStrHandle));
  37.         HLock(Handle(IDStrHandle));
  38.         FreeSpace := FreeMem;
  39.         myHeapSpace := MaxMem(FreeSpace);
  40.         NumToString(myHeapSpace, Str2);
  41.         Str2 := concat('Memory = ', Str2);
  42.         Str3 := '';
  43.         Str1 := '';
  44.         ParamText(IDStrHandle^^, Str1, Str2, Str3);
  45.         dialogP := GetNewDialog(AboutDialog, NIL, pointer(-1));
  46.         IF dialogP = NIL THEN
  47.             BEGIN
  48.                 doMessage('Dialog crash!', 'We are dead...', '', '');
  49.                 ExitToShell;
  50.             END;
  51.         initCursor;
  52.         ModalDialog(NIL, item);
  53.         DisposDialog(dialogP);
  54.         HUnlock(Handle(IDStrHandle));
  55.     END;
  56.  
  57.     PROCEDURE doQuit;
  58.     BEGIN
  59.         BackColor(whiteColor);
  60.         ForeColor(blackColor);
  61.         PenNormal;
  62.         DisposeWindow(PlotWindow);
  63.         DisposeRgn(mouseRgn);
  64.         DisposHandle(Handle(PlotDocHandle));
  65.         Finished := true;
  66.     END; {of proc}
  67.  
  68.     PROCEDURE doMenubar; {(menuResult : LongInt)}
  69.         VAR
  70.             theMenu : integer;
  71.             theItem : integer;
  72.             daName : STR255;
  73.             accItem : integer;
  74.             temp : GrafPtr;
  75.     BEGIN
  76.         theMenu := HiWord(menuResult); {menu}
  77.         theItem := LoWord(menuResult); {item}
  78.         CASE theMenu OF
  79.             AppleMenu : 
  80.                 BEGIN
  81.                     IF theItem = aAbout THEN
  82.                         doAbout
  83.                     ELSE
  84.                         BEGIN    {must be DA}
  85.                             GetItem(myMenus[AppleM], theItem, daName);
  86.                             GetPort(temp);    {protect against flacky DA}
  87.                             accItem := OpenDeskAcc(daName);
  88.                             SetPort(temp);
  89.                         END; {else}
  90.                 END; {of AppleMenu}
  91.             FileMenu : 
  92.                 BEGIN
  93.                     CASE theItem OF
  94.                         fPlot : 
  95.                             BEGIN
  96.                                 doPlot;
  97.                             END;
  98.                         fSave : 
  99.                             BEGIN
  100.                                 doSave;
  101.                             END;
  102.                         fSaveAs : 
  103.                             BEGIN
  104.                                 doSaveAs;
  105.                             END;
  106.                         fPageSet : 
  107.                             BEGIN
  108.                                 doPageSet;
  109.                             END;
  110.                         fPrint : 
  111.                             BEGIN
  112.                                 doPrint;
  113.                             END;
  114.                         fQuit : 
  115.                             BEGIN
  116.                                 doQuit;
  117.                             END;
  118.                         OTHERWISE
  119.                             BEGIN
  120.                             END;
  121.                     END; {of theitem}
  122.                 END; {of FileMenu}
  123.             EditMenu : 
  124.                 BEGIN
  125.                     IF NOT SystemEdit(theitem - 1) THEN
  126.                         BEGIN
  127.                             CASE theItem OF
  128.                                 eUndo : 
  129.                                     BEGIN
  130.                                     END;
  131.                                 eCut : 
  132.                                     BEGIN
  133.                                     END;
  134.                                 eCopy : 
  135.                                     BEGIN
  136.                                     END;
  137.                                 ePaste : 
  138.                                     BEGIN
  139.                                     END;
  140.                                 eClear : 
  141.                                     BEGIN
  142.                                     END;
  143.                                 OTHERWISE
  144.                                     BEGIN
  145.                                     END;
  146.                             END; {of case}
  147.                         END; {of system edit}
  148.                 END; {of EditMenu}
  149.             ColorMenu : 
  150.                 BEGIN {just a dummy for submenus}
  151.                 END; {of color menu}
  152.             GraphMenu : 
  153.                 BEGIN
  154.                     CheckItem(myMenus[GraphM], GraphColor, false);
  155.                     GraphColor := theitem;
  156.                     CheckItem(myMenus[GraphM], GraphColor, true);
  157.                 END; {of graph menu}
  158.             AxisMenu : 
  159.                 BEGIN
  160.                     CheckItem(myMenus[AxisM], AxisColor, false);
  161.                     AxisColor := theitem;
  162.                     CheckItem(myMenus[AxisM], AxisColor, true);
  163.                 END; {of axis menu}
  164.             BackgroundMenu : 
  165.                 BEGIN
  166.                     CheckItem(myMenus[BackgroundM], BackgroundColor, false);
  167.                     BackgroundColor := theitem;
  168.                     CheckItem(myMenus[BackgroundM], BackgroundColor, true);
  169.                 END; {of background menu}
  170.             OptionMenu : 
  171.                 BEGIN
  172.                     CheckItem(myMenus[OptionM], Option, false);
  173.                     Option := theitem;
  174.                     CheckItem(myMenus[OptionM], Option, true);
  175.                 END;
  176.             OTHERWISE
  177.                 BEGIN
  178.                 END;
  179.         END; {of theMenu}
  180.         HiliteMenu(0);    {un-hilite selected menu}
  181.     END;
  182.  
  183.     PROCEDURE doContent; {(ConEvent : EventRecord}
  184.                                     {contentWindow : windowPtr);}
  185.         VAR
  186.             localPt, globalPt : Point;
  187.             part : integer;
  188.             myRect : Rect;
  189.             control : ControlHandle;
  190.     BEGIN
  191.         IF contentWindow <> FrontWindow THEN
  192.             SelectWindow(contentWindow);
  193.         globalPt := ConEvent.where;
  194.         localPt := globalPt;        {global coord of mouse}
  195.         GlobalToLocal(localPt);     {local coord of mouse}
  196.         part := FindControl(localPt, contentWindow, control);
  197.  
  198.         IF contentWindow = PlotWindow THEN
  199.             BEGIN
  200.                 SetPort(PlotWindow);
  201.                 IF part <> 0 THEN
  202.                     BEGIN {in control}
  203.                     END;
  204.                 IF part = 0 THEN
  205.                     BEGIN    {content region}
  206.                         myRect := PlotWindow^.portRect;
  207.                         IF PtInRect(localPt, myRect) THEN
  208.                             BEGIN
  209.                             END;  {of ptInRect}
  210.                     END; { of part=0 }
  211.             END; {of contentwindow}
  212.     END;  {of proc}
  213.  
  214.     PROCEDURE doDrag; {(GrabWindow : WindowPtr}
  215.                                 {GlobalMouse : point);}
  216.     BEGIN
  217.         DragWindow(GrabWindow, GlobalMouse, DragArea);
  218.     END;
  219.  
  220.     PROCEDURE doGrow; {(ResizeWindow : WindowPtr;}
  221.                                 {Globalmouse : point;}
  222.                                 {ZoomFlg:Boolean);}
  223.         VAR
  224.             newSize : LongInt;
  225.             hsize : integer;
  226.             vsize : integer;
  227.             oldPort : GrafPtr;
  228.             myRect : rect;
  229.             tempLong : LongInt;
  230.     BEGIN
  231.         IF (ResizeWindow <> FrontWindow) THEN
  232.             SelectWindow(ResizeWindow)
  233.         ELSE
  234.             BEGIN
  235.                 IF (ZoomFlg) THEN
  236.                     BEGIN
  237.                         WITH ResizeWindow^.portRect DO
  238.                             BEGIN
  239.                                 tempLong := bottom - top;
  240.                                 newSize := BitShift(tempLong, 16);
  241.                                 newSize := newSize + (right - left);
  242.                             END;
  243.                     END
  244.                 ELSE
  245.                     newSize := GrowWindow(ResizeWindow, Globalmouse, GrowArea);
  246.                 IF newSize <> 0 THEN
  247.                     BEGIN  {grow the window}
  248.                         hsize := LoWord(newSize);
  249.                         vsize := HiWord(newSize);
  250.                         IF ResizeWindow = PlotWindow THEN
  251.                             BEGIN
  252.                                 WITH ResizeWindow^.portRect DO {Pre-Grow}
  253.                                     BEGIN
  254.                                         SetRect(VCRect, right - (SBarWidth - 1), top - 1, right + 1, bottom - (SBarWidth - 2));
  255.                                         SetRect(HCRect, left - 1, bottom - (SBarWidth - 1), right - (SBarWidth - 2), bottom + 1);
  256.                                         SetRect(GrowRect, HCRect.right, HCRect.top, VCRect.right, HCRect.bottom);
  257.                                         SetRect(PicRect, left, top, right - (SBarWidth - 1), bottom - (SBarWidth - 1));
  258.                                     END;  {of with }
  259.                                 InvalRect(VCRect);
  260.                                 InvalRect(HCRect);
  261.                                 InvalRect(GrowRect);
  262.                                 SizeWindow(ResizeWindow, hsize, vsize, TRUE); {new portRect}
  263.                                 WITH ResizeWindow^.portRect DO {Post Grow}
  264.                                     BEGIN
  265.                                         SetRect(VCRect, right - (SBarWidth - 1), top - 1, right + 1, bottom - (SBarWidth - 2));
  266.                                         SetRect(HCRect, left - 1, bottom - (SBarWidth - 1), right - (SBarWidth - 2), bottom + 1);
  267.                                         SetRect(GrowRect, HCRect.right, HCRect.top, VCRect.right, HCRect.bottom);
  268.                                         SetRect(PicRect, left, top, right - (SBarWidth - 1), bottom - (SBarWidth - 1));
  269.                                         SetRect(PageRect, left, top, right - (SBarWidth - 1), bottom - (SBarWidth - 1));
  270.                                     END;  {of with }
  271.                                 InvalRect(VCRect);
  272.                                 InvalRect(HCRect);
  273.                                 InvalRect(GrowRect);
  274.                                 InvalRect(PicRect);
  275.                             END; {of if ResizeWindow}
  276.                     END; {of grow window stuff}
  277.             END; {of if then newsize}
  278.     END;  { of proc }
  279.  
  280. END. {of unit}